# _*_ coding: utf-8 _*_
# @Time : 2020/10/27 14:50
# @Author : liupengfei
# @File : serialiers.py
from rest_framework import serializers
from apps.member.activity.models import Activity
from apps.member.stores.models import Store
from apps.member.activity.vote.models import VoteActivity


class VoteActivityBackSerialzier(serializers.ModelSerializer):
    status_text = serializers.CharField(source='get_status_display', read_only=True)
    # bg_color = serializers.CharField(source='bg_color.notes', read_only=True)
    theme = serializers.CharField(source='theme.name', read_only=True)
    vote_way = serializers.SerializerMethodField()
    vote_time = serializers.SerializerMethodField()
    merchant_name = serializers.SerializerMethodField()
    phote = serializers.SerializerMethodField()

    def get_phote(self, obj):
        return 'https://ossweb-img.qq.com/images/lol/web201310/skin/big81005.jpg'

    def get_vote_way(self, obj):
        vote = obj.vote_activity.all().first()
        for vote_way in VoteActivity.VOTE_WAY:
            if vote_way[0] == vote.vote_way:
                return vote_way[1]
        return ''

    def get_vote_time(self, obj):
        vote = obj.vote_activity.all().first()
        return vote.vote_time

    def get_merchant_name(self, obj):
        # 店铺名称
        return obj.merchant.store.all().first().name

    class Meta:
        model = Activity
        fields = '__all__'
